<html>
<head><meta charset="utf-8"><title>Advice: Program to create custom mouse bindings · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html">Advice: Program to create custom mouse bindings</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226063261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226063261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joel M. <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226063261">(Feb 11 2021 at 21:52)</a>:</h4>
<p>Hello everyone,</p>
<p>An idea for a project occurred to me a few moments ago and I wanted to see if you guys can point me in the right direction in case I want to pursuit it. </p>
<p>There might already be solutions for my idea (perhaps <em>xbindkeys</em>, <em>xev</em>, or <em>xdottools</em> could be used) but this is more about the journey than solving a problem kind of thing.</p>
<h2>The Idea</h2>
<p>I would like to use my cheap Amazon Basics mouse to do horizontal scroll. The bindings I would like to do is rightclick+scroll.</p>
<h3>How I see it functioning</h3>
<ol>
<li>The user right clicks and the right click default action is triggered (opening of a menu with options, etc)</li>
<li>The moment the scroll wheel is moved while holding the right click, the default right click action is no longer active (same as if the user lets go of the rightclick) and the scroll wheel now scrolls horizontally.</li>
</ol>
<h2>Things I am wondering</h2>
<ul>
<li>Would the program have to run as a deamon?</li>
<li>Would this lead me towards hardware drivers development?<ul>
<li>If so, what are a few good docs, blog posts, videos that introduces the topic?</li>
</ul>
</li>
</ul>
<p>Thank you all that reply! <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="226063937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226063937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226063937">(Feb 11 2021 at 21:58)</a>:</h4>
<p>you might find <a href="https://crates.io/crates/device_query">https://crates.io/crates/device_query</a> helpful</p>



<a name="226063955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226063955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226063955">(Feb 11 2021 at 21:58)</a>:</h4>
<p>(or some other library, I haven't used that particular one)</p>



<a name="226121672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226121672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226121672">(Feb 12 2021 at 10:46)</a>:</h4>
<p><span class="user-mention" data-user-id="389055">@Joel M.</span> hi again :) which platform are you targeting for such a tool? I see you mention X11 tools so I'll assume Linux.</p>
<p>I gave a quick look not long ago and tried to play a bit with <code>libevdev</code>, here's a basic script to remap <a href="https://gist.github.com/apiraino/25ca3ff037c66bacc18f2ae6342c48a1">keystrokes to mouse movements</a>.</p>
<p>Also <code>libinput</code> which (in my limited understanding) is the recommended kernel interface to handle HID input and also supports Wayland. Here's a <a href="https://pypi.org/project/python-libinput/">python libinput library</a>. Libinput is documented <a href="https://wayland.freedesktop.org/libinput/doc/latest/features.html">here</a></p>



<a name="226121682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226121682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226121682">(Feb 12 2021 at 10:46)</a>:</h4>
<p>side note: I'd found useful prototyping with something like python (i.e. a language to quickly iterate over ~100 lines of code) because I discovered immediately various usability issues when trying to handle streams of input signals.</p>



<a name="226121924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226121924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226121924">(Feb 12 2021 at 10:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings/near/226063937">said</a>:</p>
<blockquote>
<p>you might find <a href="https://crates.io/crates/device_query">https://crates.io/crates/device_query</a> helpful</p>
</blockquote>
<p>worth mentioning that (on the surface) this library seems to allow querying but not handling input signals. Also requires <code>libx11-*</code> so it's X11 only.<br>
(note, I'm lying: Wayland supports Xwayland to handle X11 applications)</p>



<a name="226122202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226122202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226122202">(Feb 12 2021 at 10:52)</a>:</h4>
<p>Xwayland is pretty restricted compared to regular Xorg. For example programs can't communicate with each other. I don't know if it allows getting mouse input outside of the program window. Wayland has been designed to make this kind of things impossible without extensions. This ensures that a keylogger is useless when it is part of a sandboxed program. Which wayland compositor are you using? It may have an extension to allow what you want.</p>



<a name="226123917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226123917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226123917">(Feb 12 2021 at 11:12)</a>:</h4>
<p>I'm on <code>wlroots</code> (+sway, xwayland disabled).<br>
Right, I should have mentioned that I use xwayland only as last resort for those X11 applications standing on old versions of GUI toolkits that were not updated to support Wayland.</p>
<blockquote>
<p>I don't know if it allows getting mouse input outside of the program window.</p>
</blockquote>
<p>hmm ... (never tried but) by "program window" would that imply that a cli application to remap libinput events wouldn't work either?</p>



<a name="226124547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226124547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226124547">(Feb 12 2021 at 11:19)</a>:</h4>
<p>Correct. I did find <a href="https://www.codedbearder.com/posts/writing-keyboard-remapper-wayland/">https://www.codedbearder.com/posts/writing-keyboard-remapper-wayland/</a> though which requires you to change the permission for the <code>/dev/input</code> device files to make them user readable, thereby circumventing this. Sway also has some input configuration (<code>man sway-input</code>) but it doesn't seem to support this remapping you want.</p>



<a name="226125000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Advice%3A%20Program%20to%20create%20custom%20mouse%20bindings/near/226125000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Advice.3A.20Program.20to.20create.20custom.20mouse.20bindings.html#226125000">(Feb 12 2021 at 11:25)</a>:</h4>
<p>Ha! I remember that blog post :-) <br>
Thanks for the info, though!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>